<?php

namespace app\admin\model\user;

//use think\Model;
use app\admin\model\User;
use app\api\model\v1\CoursesCategory;
use app\api\model\v1\MechanismCategory;
use think\Model;
use think\Db;

class Teacher extends Model
{

    

    

    // 表名
    protected $name = 'user_teacher';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'teacher_status_text',
        'status_text'
    ];
    

    
    public function getTeacherStatusList()
    {
        return ['1' => __('Teacher_status 1'), '2' => __('Teacher_status 2'), '3' => __('Teacher_status 3')];
    }

    public function teacherIshomeList()
    {
        return ['0' => __('不推荐'), '1' => __('推荐')];
    }


    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
    }


    public function getTeacherStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['teacher_status']) ? $data['teacher_status'] : '');
        $list = $this->getTeacherStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function getCategoryList()
    {
//        $list = MechanismCategory::order('weigh asc')->field('id,name')->select();
        $list = Db::name('mechanism_category')->order('weigh asc')->where('pid',0)->field('id,name')->select();
        $categorydata = [];
        foreach ($list as $k => $v) {
            $categorydata[$v['id']] = $v;
        }
        return $categorydata;
    }

}
